package com.yangchoi.jetpackcompose.ui.main.viewmodel

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.yangchoi.lib_base.base.BaseViewModel
import com.yangchoi.lib_base.network.ApiService
import com.yangchoi.lib_base.network.entity.UserConfigEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MineViewModel @Inject constructor(private val apiService: ApiService) : BaseViewModel() {
    var viewState by mutableStateOf(MineState())
        set

    fun dispatch(event: MineEvent){
        when(event){
            MineEvent.OnInitMine -> {
                launchFlow(
                    requestBlock = { apiService.getUserConfig() },
                    response = {
                        viewState = viewState.copy(userConfigEntity = it)
                    }
                )
            }
        }
    }
}

data class MineState(
    var userConfigEntity: UserConfigEntity? = null
)

sealed class MineEvent{
    object OnInitMine : MineEvent()
}